const mongoose = require('mongoose')

const schema = new mongoose.Schema({
    articleId:{
        type: mongoose.SchemaTypes.ObjectId,
        require: true,
        ref: 'Article'
    },
    commentUserId:{
        type: mongoose.SchemaTypes.ObjectId,
        ref: 'User'
    },
    commentUserName:{
        type: String,
    },
    commentContent: {
        type: String
    },
    like: [{
        type: mongoose.SchemaTypes.ObjectId,
        ref: 'User'
    }],
    publishTime: {
        type: Number
    },
    comment:[{
        responseUserId:{
            type: mongoose.SchemaTypes.ObjectId,
            ref: 'User'
        },
        responseUserName:{
            type: String,
            require: true
        },
        responseWhoId:{
            type: mongoose.SchemaTypes.ObjectId,
            ref: 'User'
        },
        responseWhoName:{
            type: String
        },
        responseContent:{
            type: String
        },
        replyTime:{
            type:Number
        },
        like: [{
            type: mongoose.SchemaTypes.ObjectId,
            ref: 'User'
        }],
    }]
}, {timestamps: {createdAt: 'created', updatedAt: 'updated'}})

module.exports = mongoose.model('Comment', schema)